(function () {
    'use strict';

    angular
    .module('app')
    .factory('APIOrderService', APIOrderService);

    APIOrderService.$inject = ['$http', '$q', '$timeout', 'CacheFactory', 'ENUM'];

    function APIOrderService($http, $q, $timeout, CacheFactory, ENUM) {

        var service = new APIEndpoint( $http, $q, $timeout, CacheFactory, 'APIOrderService' );
        service.getOne = function( params ) {
            return this.fetch( '/weixin/order/getOne', params, false, function(res){
                return ENUM.ERROR_CODE.OK == res.data.code ? res.data.data : null;
            });
        };

        service.getList = function( params ) {
            return this.fetch( '/weixin/order/getList', params, false, function(res){
                return ENUM.ERROR_CODE.OK == res.data.code ? res.data.data : null;
            });
        };

        service.confirmReceipt = function( params ) {
            return this.fetch( '/weixin/order/confirmReceipt', params, false, function(res){
                return ENUM.ERROR_CODE.OK == res.data.code ? true : false;
            });
        };

        service.cancel = function( params ) {
            return this.fetch( '/weixin/order/cancel', params, false, function(res){
                return ENUM.ERROR_CODE.OK == res.data.code ? true : false;
            });
        };

        service.comment = function( params ) {
            return this.fetch( '/weixin/order/comment', params, false, function(res){
                return ENUM.ERROR_CODE.OK == res.data.code ? true : false;
            });
        };

        service.getSubTotal = function( params ) {
            return this.fetch( '/weixin/order/getSubTotal', params, false, function(res){
                return ENUM.ERROR_CODE.OK == res.data.code ? res.data.data : null;
            });
        };

        service.getCheckPrice = function( params ) {
            return this.fetch( '/weixin/order/getCheckPrice', params, false, function(res){
                return ENUM.ERROR_CODE.OK == res.data.code ? res.data.data : null;
            });
        };

        service.getPrePrice = function( params ) {
            return this.fetch( '/weixin/order/getPrePrice', params, false, function(res){
                return ENUM.ERROR_CODE.OK == res.data.code ? res.data.data : null;
            });
        };

        service.getNeedPay = function( params ) {
            return this.fetch( '/weixin/order/getNeedPay', params, false, function(res){
                return ENUM.ERROR_CODE.OK == res.data.code ? res.data.data : null;
            });
        };

        return service;
    }

})();
